/*
This file is part of buco.  
Copyright (c) 2012 Christopher Pawelzik <christopher@cpawelzik.com>

Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php 
*/ 
package buco.core.api;

import java.util.*;

/**
 * This class is used by plug-ins to register new integrity check strategies. 
 */
public final class IntegrityCheckRegistry {
	
	private static List<Class<IntegrityCheck>> integrityChecks; 
	
	static {
		integrityChecks = new ArrayList<Class<IntegrityCheck>>(); 
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" }) 
	public static synchronized void register(Class integrityCheck)  {
		integrityChecks.add(integrityCheck);
	}
	
	/**
	 * Creates a list of instances of the currently registered integrity check classes. 
	 */
	public static synchronized List<IntegrityCheck> createIntegrityChecks() {
		ArrayList<IntegrityCheck> instances = new ArrayList<IntegrityCheck>(); 
		for(Class<IntegrityCheck> clazz : integrityChecks) {
			try {
				instances.add(clazz.newInstance());
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} 			
		}
		return instances;
	}
}
